package com.itheima.tlias84.utils;

import lombok.Data;

@Data
public class ResultUtil {
    //私有化构造器
    private ResultUtil() {
    }

    private Integer code;
    private String msg;
    private Object data;

//    成功or失败的方法

    /**
     * 默认成功方法
     *
     * @return 成功的返回
     */
    public static ResultUtil success() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = "成功";
        return resultUtil;
    }

    /**
     * 携带自定义成功信息的返回方法
     * @param message 自定义信息
     * @return 响应信息
     */
    public static ResultUtil success(String message) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = message;
        return resultUtil;
    }

    /**
     * 携带数据的成功方法
     * @param date 数据
     * @return 响应信息
     */
    public static ResultUtil success(Object date) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = "成功";
        resultUtil.data = date;
        return resultUtil;
    }

    /**
     * 批量处理成功方法
     * @param number 批量处理的数量
     * @param date 数据
     * @return 响应信息
     */
    public static ResultUtil success(int number,Object date) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = number;
        resultUtil.msg = "成功";
        resultUtil.data = date;
        return resultUtil;
    }

//    TODO 完成三个失败的方法
    public static ResultUtil fail() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = "失败";
        return resultUtil;
    }
    public static ResultUtil fail(String message) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = message;
        return resultUtil;
    }

    public static ResultUtil fail(String message,Object object) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = message;
        resultUtil.data=object;
        return resultUtil;
    }
    public static ResultUtil fail(Object date) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = "成功";
        resultUtil.data = date;
        return resultUtil;
    }

    /**
     * 批量处理失败方法
     * @param number 批量处理的数量
     * @param date 数据
     * @return 响应信息
     */
    public static ResultUtil fail(int number,Object date) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = "成功批量处理："+number;
        resultUtil.data = date;
        return resultUtil;
    }



}

